package com.timothy.junk.adapter;

import android.content.Context;
import android.content.SharedPreferences;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.EditText;
import android.widget.ImageButton;
import android.widget.TextView;
import android.widget.ToggleButton;
import com.sina.util.StringUtil;
import com.timothy.junk.R;
import com.timothy.junk.cbond.bean.CBondNotify;

import java.util.HashMap;
import java.util.List;

public class CBondNotifyAdaptor extends BaseAdapter {
	private Context mContext;
	private SharedPreferences sp;
	private List<CBondNotify> listItems;
	private LayoutInflater mInflater;

	static class ViewHolder{
		public TextView sCBondIndex;
        public TextView sCBondName;
		public EditText sCeilDiscount;
		public ImageButton sAddCeil;
		public ToggleButton sIsNotify;
	}

	public CBondNotifyAdaptor(Context context, List<CBondNotify> data,SharedPreferences sp) {
		this.mContext = context;
		mInflater = LayoutInflater.from(context); 
		this.listItems = data;
	}

	
	@Override
	public int getCount() {
		return listItems.size();
	}

	@Override
	public Object getItem(int arg0) {
		return null;
	}

	@Override
	public long getItemId(int arg0) {
		return 0;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {

		ViewHolder holder;  
        if (convertView == null){  
            holder = new ViewHolder();  
            convertView = mInflater.inflate(R.layout.cbond_notify_list_item, null);
            
            holder.sCBondIndex = (TextView) convertView.findViewById(R.id.sCBondIndex);
			holder.sCBondName = (TextView) convertView.findViewById(R.id.sCBondName);
			holder.sCeilDiscount = (EditText) convertView.findViewById(R.id.sCeilDiscount);
			holder.sAddCeil = (ImageButton) convertView.findViewById(R.id.sAddCeil);
			holder.sIsNotify = (ToggleButton) convertView.findViewById(R.id.sIsNotify);
			
            convertView.setTag(holder);  
        }else {  
            holder = (ViewHolder) convertView.getTag();  
        }

        CBondNotify bean = listItems.get(position);
		holder.sCBondIndex.setText(String.valueOf(position+1));
		holder.sCBondName.setText(bean.getBond_name());
		holder.sCeilDiscount.setText(String.valueOf(bean.getCeilDisount()));
		if(bean.isNotify()){
			holder.sIsNotify.setChecked(true);
		}else{
			holder.sIsNotify.setChecked(false);
		}

        return convertView; 
        
	}

}
